package com.uphone.magicleafteacher.pro.activity.retellinglearn;

import android.view.View;

import com.radish.baselibrary.Intent.IntentUtils;
import com.uphone.magicleafteacher.MyApp;
import com.uphone.magicleafteacher.base.BaseListActivity;
import com.uphone.magicleafteacher.http.ApiService;
import com.uphone.magicleafteacher.pro.activity.JobsActivity;
import com.uphone.magicleafteacher.pro.adapter.RetellingLearAdapter;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.GsonUtils;
import com.uphone.magicleafteacher.vo.RetellingLearnBean;
import com.uphone.magicleafteacher.vo.WorkcorrectionEvent;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class RetellingLearnActivity extends BaseListActivity<RetellingLearnBean.ReadBookListBean, RetellingLearAdapter> {

    @Override
    protected void initLayoutBefore() {
        super.initLayoutBefore();
        isEventBus = true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefresh(WorkcorrectionEvent outGroupEvent) {
        //刷新
        initData();
    }
    @Override
    protected Observable<ResponseBody> loadData(ApiService apiService) {
        return MyApp.apiService(ApiService.class)
                .bookReadList(CommonUtil.getTeacherId(), page + "", "10");
    }

    @Override
    protected List<RetellingLearnBean.ReadBookListBean> getDataList(String json) {
        RetellingLearnBean bean = GsonUtils.getGson().fromJson(json, RetellingLearnBean.class);
        if (bean != null)
            return bean.getReadBookList();
        return null;
    }

    @Override
    protected void itemClick(RetellingLearAdapter adapter, View view, int position) {
        IntentUtils.getInstance().with(this, JobsActivity.class)
                .putInt("status", mAdapter.getItem(position).getReadStatus())
                .putInt("id", mAdapter.getItem(position).getReadId())
                .start();
    }

    @Override
    protected RetellingLearAdapter initAdapter() {
        return new RetellingLearAdapter();
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected void initTitle() {
        initTitle("阅读点评");
    }
}
